package top.lyc829.leetcode.T560;

public class Solution {
    public int subarraySum(int[] nums, int k) {
        int len = nums.length;
        int count = 0;
        int[] sum = new int[len + 1];
        sum[0] = 0;

        for (int i = 0; i < len; i++) {
            sum[i + 1] = sum[i] + nums[i];
        }

        for (int i = 0; i < len; i++) {

            for (int j = i; j < len; j++) {

                if (sum[j + 1] - sum[i] == k) {
                    count++;
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        int res = s.subarraySum(new int[]{1}, 0);

        System.out.println(res);
    }
}
